package com.SunSoft.PhoneRemoteControl;

import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.text.Editable;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.Toast;
import java.lang.reflect.Field;
import java.sql.Date;
import java.text.SimpleDateFormat;

final class bl
  implements DialogInterface.OnClickListener
{
  public final void onClick(DialogInterface paramDialogInterface, int paramInt)
  {
    Object localObject3;
    Object localObject4;
    Object localObject1 = this.b.getText().toString();
    Object localObject2 = this.c.getText().toString();
    if (this.a.C)
    {
      localObject3 = localObject1;
      if (MainControl.d)
        break label1142;
      if (!(this.a.C))
        break label174;
      localObject4 = "New device";
      localObject2 = localObject1;
      localObject1 = localObject4;
    }
    while (true)
    {
      localObject4 = localObject3;
      if (localObject3 == null)
        localObject4 = "";
      paramInt = 0;
      if (paramInt >= MainControl.y(this.a).length)
      {
        localObject3 = "";
        paramInt = 1;
        if ((!(((String)localObject4).equals(""))) && (paramInt != 5))
          break label294;
      }
      label273: label294: 
      do
        try
        {
          while (true)
          {
            while (true)
            {
              while (true)
              {
                localObject1 = paramDialogInterface.getClass().getSuperclass().getDeclaredField("mShowing");
                ((Field)localObject1).setAccessible(true);
                ((Field)localObject1).set(paramDialogInterface, Boolean.valueOf(false));
                if (paramInt != 5)
                  break label273;
                Toast.makeText(this.a, this.a.getString(2131099805), 0).show();
                return;
                localObject3 = localObject2;
              }
              label174: localObject1 = localObject2;
              localObject2 = "新设备";
            }
            if (!(MainControl.z(this.a)[this.a.m].equals(MainControl.y(this.a)[paramInt].c)))
              break;
            localObject3 = MainControl.y(this.a)[paramInt].a;
          }
          paramInt += 1;
        }
        catch (SecurityException paramDialogInterface)
        {
          while (true)
            paramDialogInterface.printStackTrace();
        }
        catch (NoSuchFieldException paramDialogInterface)
        {
          while (true)
            paramDialogInterface.printStackTrace();
        }
        catch (IllegalArgumentException paramDialogInterface)
        {
          while (true)
            paramDialogInterface.printStackTrace();
        }
        catch (IllegalAccessException paramDialogInterface)
        {
          while (true)
            paramDialogInterface.printStackTrace();
          Toast.makeText(this.a, this.a.getString(2131099804), 0).show();
          return;
        }
      while (this.a.F);
      this.a.F = true;
      localObject4 = MainControl.c();
      String str1 = MainControl.c();
      String str2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(System.currentTimeMillis()));
      Object[] arrayOfObject = new Object[12];
      arrayOfObject[1] = localObject4;
      arrayOfObject[2] = Integer.valueOf(paramInt);
      arrayOfObject[3] = localObject2;
      arrayOfObject[4] = this.d.getText().toString();
      arrayOfObject[5] = localObject1;
      arrayOfObject[6] = this.e.getText().toString();
      arrayOfObject[7] = this.f.getText().toString();
      arrayOfObject[8] = "0";
      if (MainControl.d)
      {
        arrayOfObject[9] = "1";
        arrayOfObject[10] = str1;
        arrayOfObject[11] = str2;
      }
      try
      {
        while (true)
        {
          do
          {
            localObject1 = MainControl.i(this.a);
            if (MainControl.d)
              localObject1 = MainControl.f(this.a);
            ((SQLiteDatabase)localObject1).execSQL("insert into control_list (ID,define_ID,control_type," + this.a.w + "," + this.a.v + ",name_en,brand_en,control_model,control_version,come_from,device_ID,update_time) values (?,?,?,?,?,?,?,?,?,?,?,?) ", arrayOfObject);
            localObject2 = MainControl.f(this.a).rawQuery("select ID,define_ID,control_ID,code_str,dis_ch,dis_en,note,order_id  from button_data where define_ID = ?", new String[] { localObject3 });
            if (((Cursor)localObject2).moveToNext())
              break label970;
            ((Cursor)localObject2).close();
            localObject1 = this.d.getText().toString();
            if ((MainControl.d) && (!(((String)localObject1).equals(""))) && (!(((String)localObject1).contains("|"))))
              if (MainControl.f(this.a).rawQuery("select ID,brand_ch,control_type,brand_en from brand_list where Control_type = ? and brand_ch= ? ", new String[] { String.valueOf(paramInt), this.d.getText().toString() }).getCount() == 0)
              {
                localObject1 = new Object[4];
                localObject1[1] = Integer.valueOf(paramInt);
                localObject1[2] = this.d.getText().toString();
                localObject1[3] = this.e.getText().toString();
                MainControl.f(this.a).execSQL("insert into brand_list (ID,control_type,brand_ch,brand_en) values (?,?,?,?) ", localObject1);
              }
            Toast.makeText(this.a, this.a.getString(2131099802), 0).show();
            if (!(MainControl.d))
            {
              this.a.b();
              paramInt = 0;
              localObject1 = MainControl.i(this.a).rawQuery("select  ID,control_type from control_list where ID>? order by ID Desc", new String[] { "0" });
              if (((Cursor)localObject1).moveToNext())
                paramInt = ((Cursor)localObject1).getInt(((Cursor)localObject1).getColumnIndex("ID"));
              if (paramInt > 0)
              {
                localObject2 = new Intent(this.a, Show_Control.class);
                ((Intent)localObject2).putExtra("con_id", String.valueOf(paramInt));
                ((Intent)localObject2).putExtra("do_type", "2");
                this.a.startActivity((Intent)localObject2);
              }
              MainControl.a("Test", "find_id:" + String.valueOf(paramInt));
              MainControl.a("Test", "find_Cursor:" + String.valueOf(((Cursor)localObject1).getCount()));
            }
            localObject1 = paramDialogInterface.getClass().getSuperclass().getDeclaredField("mShowing");
            ((Field)localObject1).setAccessible(true);
            ((Field)localObject1).set(paramDialogInterface, Boolean.valueOf(true));
            paramDialogInterface.dismiss();
            this.a.F = false;
            return;
            arrayOfObject[9] = "2";
          }
          while (!(MainControl.f));
          arrayOfObject[9] = "3";
        }
        label970: localObject3 = new Object[8];
        localObject3[1] = localObject4;
        localObject3[2] = Integer.valueOf(0);
        localObject3[3] = ((Cursor)localObject2).getString(((Cursor)localObject2).getColumnIndex("code_str"));
        localObject3[4] = ((Cursor)localObject2).getString(((Cursor)localObject2).getColumnIndex("dis_ch"));
        localObject3[5] = ((Cursor)localObject2).getString(((Cursor)localObject2).getColumnIndex("dis_en"));
        localObject3[6] = ((Cursor)localObject2).getString(((Cursor)localObject2).getColumnIndex("note"));
        localObject3[7] = Integer.valueOf(((Cursor)localObject2).getInt(((Cursor)localObject2).getColumnIndex("order_ID")));
        label1142: ((SQLiteDatabase)localObject1).execSQL("insert into button_data (ID,define_ID,control_ID,code_str,dis_ch,dis_en,note,order_ID) values (?,?,?,?,?,?,?,?) ", localObject3);
      }
      catch (Exception paramDialogInterface)
      {
        while (true)
        {
          while (true)
          {
            paramDialogInterface.printStackTrace();
            Toast.makeText(this.a, this.a.getString(2131099803), 0).show();
          }
          localObject4 = localObject1;
          localObject1 = localObject2;
          localObject2 = localObject4;
        }
      }
    }
  }
}